var index;

$(function(){
	index = parent.layer.getFrameIndex(window.name);
	
	$('input:radio[name="sex"][value="'+$("#sexVal").val()+'"]').attr('checked',true);
	$('input:radio[name="maritalStatus"][value="'+$("#maritalStatusVal").val()+'"]').attr('checked',true);
	$('input:radio[name="lectureNotice"][value="'+$("#lectureNoticeVal").val()+'"]').attr('checked',true);
	$('input:radio[name="jdq"][value="'+$("#jdqVal").val()+'"]').attr('checked',true);
	$('input:radio[name="ifFifteenRevisit"][value="'+$("#ifFifteenRevisitVal").val()+'"]').attr('checked',true);
	$('input:radio[name="ifAssetsMillion"][value="'+$("#ifAssetsMillionVal").val()+'"]').attr('checked',true);
	
	getCheckBoxServiceInfo("#intentionService");
	getCheckBoxCustType("#custType");
	
	if($('#intentionServiceVal').val()){
		var intentionServiceArray = $('#intentionServiceVal').val().split(';');
		$.each(intentionServiceArray,function(index,value){
			var option = new Option(value.split(',')[1], value.split(',')[0], true, true);
			$('#intentionService').append(option);
		});
		$('#intentionService').trigger('change')
	}
	
	if($('#custTypeVal').val()){
		var custTypeArray = $('#custTypeVal').val().split(';');
		$.each(custTypeArray,function(index,value){
			var option = new Option(value.split(',')[1], value.split(',')[0], true, true);
			$('#custType').append(option);
		});
		$('#custType').trigger('change')
	}
	
	
	$('.submit span').on('click',function(){
		
		if($('#mobile').val()=='' || $('#email1').val()==''){
			parent.layer.msg('手机、邮箱必须填写');
			return false;
		}
		
		if($('#revisitDateVal').val()!='' && $('#revisitDate').val()==''){
			parent.layer.msg('回访时间不能为空');
			return false;
		}
		
		$(this).css('pointer-events','none').css('opacity','0.2');
		var intentionServiceStr;
		if($('#intentionService').val()){
			intentionServiceStr = $('#intentionService').val().join();
		}else{
			intentionServiceStr = '';
		}
		
		var custTypeStr;
		if($('#custType').val()){
			custTypeStr = $('#custType').val().join();
		}else{
			custTypeStr = '';
		}
		
		var noticeArrayData = $.extend({},{'intentionServiceStr':intentionServiceStr, 'custTypeStr':custTypeStr},$('#memberForm').serializeObject());
		$.ajax({
			url : webroot+ "/member/updateMemberInfo.ajax",
			data : noticeArrayData,
			type : 'POST',
			dataType : 'json',
			success : function(dataResult) {
				parent.layer.msg(dataResult.msg);
				$('.submit span').css('pointer-events','auto').css('opacity','1');
				if(dataResult.type=='2'){
					parent.memberTable().draw();
					parent.layer.close(index);
				}
			}
		});
	});
	
});


